package lib.core.utils
{
	import lib.core.controller.RequestUrlInfo;
	
	public class ValueObjectUtil
	{
		public static function objectToVO(obj:Object,type:Class):Object
		{
			var vo:Object = new type();
			
			for(var prop in obj)
			{
				if (vo.hasOwnProperty(prop))
				{
					vo[prop] = obj[prop];
				}
			}
			return vo;
		}
		
		public static function resultSetItemToVO(obj:Object, type:Class):Object
		{
			var vo:Object = new type();
			
			for(var prop in obj)
			{
				var propName:String = resultSetFieldToVOProp(String(prop));
				if (vo.hasOwnProperty(propName))
				{
					vo[propName] = obj[prop];
				}
			}
			return vo;
		}
		
		public static function resultSetFieldToVOProp(name:String):String
		{
			name = name.toLowerCase();
			var temp:Array = name.split('_');
			var i:Number = 0;
			name = '';
			for each (var word:String in temp)
			{
				if (i > 0)
				{
					name = name + RequestUrlInfo.ucFirst(word);	
				} else {
					name = word;
					i++;		
				}
			}
			return name;
		}
	}
}